package com.share.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.share.domain.Content;
import com.share.domain.Result;
import com.share.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * @program: share-admin
 * 描述：
 * @author: XLX
 * @create: 2022-12-07 14:16
 **/
@RestController
@RequestMapping("/sys/content")
public class ContentController extends BaseController{


    @Autowired
    ContentService contentService;


    @GetMapping("/info/{id}")
    public Result info(@PathVariable(name = "id") Long id){
        Content content = contentService.getInfoById(id);

        return Result.succ(content);
    }


    @GetMapping("/list")
    public Result list(Content content){

        Page<Content> page = contentService.findPage(content,getPage());

        return Result.succ(page);
    }




    @PostMapping("/save")
    public Result save(@Validated @RequestBody Content content){


        contentService.save(content);
        return Result.succ(content);
    }


    @PostMapping("/update")
    public Result update(@Validated @RequestBody Content content){
        contentService.updateById(content);
        return Result.succ(content);
    }


    @PostMapping("/delete")
    @Transactional
    public Result delete(@RequestBody Long[] ids){
        //删除角度
        contentService.removeByIds(Arrays.asList(ids));

        return Result.succ("内容删除成功");

    }





}